import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:oli/page/order/no_contronc/main.dart';
import 'package:oli/shared/size_fit.dart';
import 'package:oli/shared/theme.dart';
import 'package:oli/viewmodel/text_view_model.dart';
import 'package:provider/provider.dart';

class OrderPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // return Text("dddd");
    return OrderBody();
  }
}

class OrderBody extends StatefulWidget {
  @override
  _OrderBodyState createState() => _OrderBodyState();
}

class _OrderBodyState extends State<OrderBody> {

  TextEditingController textControl = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    textControl.text = '122';
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          FlatButton(
            child: Text("btn"),
            onPressed: () {
              Navigator.of(context).pushNamed(NoCon.routeName, arguments: "dddd");
            },
          ),
          RaisedButton(
            child: Text("btn"),
            onPressed: () {
              Navigator.of(context).pushNamed(NoCon.routeName, arguments: "dddd");
            },
          ),
          Consumer<TextViewModel>(
            builder: (ctx, vm, child) {
              return TextField(
                controller: textControl,
                onChanged: (value) {
                  vm.text = value;
                },
              );
            },
          ),
          Selector<TextViewModel, TextViewModel>(
            selector: (ctx, counterVM) => counterVM,
            builder: (ctx, counterVM, child){
              return Column(
                children: <Widget>[
                  Text(counterVM.text),
                  TextField(
                    onChanged: (value){
                      counterVM.text = value;
                    },
                  ),
                ],
              );
            },
            child: Icon(Icons.add),
            shouldRebuild: (prev, next) {
              return true;
            },
          ),
          MyText(),
        ],
      ),
    );
  }
}

class MyText extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String inputValue = Provider.of<TextViewModel>(context).text;

    return Text(inputValue);
  }
}
